﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
namespace DictonaryGUI
{
    /// <summary>
    /// Interaction logic for DoTranslation.xaml
    /// </summary>
    public partial class DoTranslation : Window
    {
        private string dic = "";
        private string[] lines;
        private int lang = 0;
        private string lastex = "";
        
        public DoTranslation(string path)
        {
            InitializeComponent();
            this.dic = path;
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            
            string ex = this.textBox1.Text;
            if(lastex!=ex)
            {
                this.listView1.Items.Clear();
                this.lastex = ex;
            }
            
            if(ex=="")
                listView1.Visibility = Visibility.Hidden;
            else
            {
                foreach (string line in this.lines)
                {
                    string[] exs = line.Split('*');
                    if (exs[lang].Contains(ex))
                    {
                       this.listView1.Visibility = Visibility.Visible;
                       if (lang == 0)
                           this.listView1.Items.Add(new {FL=exs[lang], SL=exs[lang+1]});
                       else
                           this.listView1.Items.Add(new { FL = exs[lang], SL =  exs[lang-1]});
                    }
                }
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            StreamReader sr = new StreamReader(this.dic);
            string full = sr.ReadToEnd();
            this.lines = full.Split(new string[] {"\r\n"}, StringSplitOptions.None);
            sr.Close();

        }

        private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
    }
}
